package com.acce.gxsc.page.outCar.list;

import com.acce.gxsc.model.WorkModel;
import com.acce.gxsc.model.loaclBean.ResultBean;
import com.acce.gxsc.model.netBean.InCarListBean1;
import com.acce.sdk.base.mvp.BasePresenter;
import com.acce.sdk.utils.ToastUtils;
import rx.Subscriber;

/**
 * Created by huxley on 2017/5/26.
 */
public class ToOutCarListPresenter extends BasePresenter<ToOutCarListView> {
  //  String  time;
  //   String  direction = "";
    boolean isLoadOver;
    int page;
    boolean hasNextPage=true;
    public void loadCarInMarketList(String queryTime, final boolean isLoadMore) {
       if (mViewRef != null && isLoadMore && isLoadOver) {
            getView().setRefreshing(false);
            return;
        }
        if (!isLoadMore) {
            isLoadOver = false;
            page=1;
        }else{
            if(!hasNextPage){
                ToastUtils.show("没有下一页数据");
                return;
            }
        }
        WorkModel.getInstance().loadCarInMarketList2(page,queryTime).subscribe(new Subscriber<ResultBean<InCarListBean1>>() {
            @Override
            public void onStart() {
                if (mViewRef != null) {
                    getView().setRefreshing(true);
                }
            }

            @Override
            public void onNext(ResultBean<InCarListBean1> datas) {
                if (mViewRef != null) {
                    if (!"200".equals(datas.returnCode)) {
                        ToastUtils.show(datas.returnMsg);
                        return;
                    }
                    if (datas.result.inCarList.list == null || datas.result.inCarList.list.size() <= 0) {
                        isLoadOver = true;
                        ToastUtils.show("没有更多");
                        if (isLoadMore) {
                            return;
                        }
                    } else {
                        if(datas.result.inCarList.hasNextPage) {
                            page = datas.result.inCarList.nextPage;
                            hasNextPage=true;
                        }else {
                            hasNextPage=false;
                        }
                    }
                    getView().loadCarInMarketListSuccess(isLoadMore, datas.result.inCarList.list,datas.result.inCarList.total);
                }
            }

            @Override
            public void onCompleted() {
                if (mViewRef != null) {
                    getView().setRefreshing(false);
                }
            }

            @Override
            public void onError(Throwable e) {
                if (mViewRef != null) {
                    e.printStackTrace();
                    getView().setRefreshing(false);
                }
            }
        });
    }
/*
    public void loadCarInMarketCount(String queryTime) {
        WorkModel.getInstance().loadCarInMarketCount(queryTime, "30").subscribe(new Subscriber<ResultBean<InCarListBean>>() {
            @Override
            public void onStart() {
                if (mViewRef != null) {
                    getView().setRefreshing(true);
                }
            }

            @Override
            public void onNext(ResultBean<InCarListBean1> datas) {
                if (mViewRef != null) {
                    getView().loadCarInMarketCount(datas.result.cartotal.totalCar);
=======
>>>>>>> origin/master:app/src/main/java/com/acce/iocard/page/outCar/list/ToOutCarListPresenter.java
                }
            }

            @Override
            public void onCompleted() {
                if (mViewRef != null) {
                    getView().setRefreshing(false);
                }
            }

            @Override
            public void onError(Throwable e) {
                if (mViewRef != null) {
                    e.printStackTrace();
                    getView().setRefreshing(false);
                }
            }
        });
    }*/
}
